var egret = window.egret;var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var core;
(function (core) {
    var BaseScene = (function () {
        function BaseScene() {
            this._layers = new Array();
        }
        BaseScene.prototype.onEnter = function () {
        };
        BaseScene.prototype.onExit = function () {
            core.App.ViewManager.closeAll();
            this.removeAllLayer();
        };
        BaseScene.prototype.enterFrame = function (time) {
        };
        BaseScene.prototype.addLayer = function (layer) {
            if (layer instanceof core.BaseSpriteLayer) {
                core.App.StageUtils.getStage().addChild(layer);
                this._layers.push(layer);
            }
            else if (layer instanceof core.BaseEuiLayer) {
                core.App.StageUtils.getUIStage().addChild(layer);
                this._layers.push(layer);
            }
        };
        BaseScene.prototype.addLayerAt = function (layer, index) {
            if (layer instanceof core.BaseSpriteLayer) {
                core.App.StageUtils.getStage().addChildAt(layer, index);
                this._layers.push(layer);
            }
            else if (layer instanceof core.BaseEuiLayer) {
                core.App.StageUtils.getUIStage().addChildAt(layer, index);
                this._layers.push(layer);
            }
        };
        BaseScene.prototype.removeLayer = function (layer) {
            if (layer instanceof core.BaseSpriteLayer) {
                core.App.StageUtils.getStage().removeChild(layer);
                this._layers.splice(this._layers.indexOf(layer), 1);
            }
            else if (layer instanceof core.BaseEuiLayer) {
                core.App.StageUtils.getUIStage().removeChild(layer);
                this._layers.splice(this._layers.indexOf(layer), 1);
            }
        };
        BaseScene.prototype.layerRemoveAllChild = function (layer) {
            if (layer instanceof core.BaseSpriteLayer) {
                layer.removeChildren();
            }
            else if (layer instanceof core.BaseEuiLayer) {
                layer.removeChildren();
            }
        };
        BaseScene.prototype.removeAllLayer = function () {
            while (this._layers.length) {
                var layer = this._layers[0];
                this.layerRemoveAllChild(layer);
                this.removeLayer(layer);
            }
        };
        return BaseScene;
    }());
    core.BaseScene = BaseScene;
    __reflect(BaseScene.prototype, "core.BaseScene");
})(core || (core = {}));
var PhyScene = (function (_super) {
    __extends(PhyScene, _super);
    function PhyScene() {
        var _this = _super.call(this) || this;
        _this._world = null;
        _this._debug = null;
        _this._step = 30;
        _this._p2m = PhyScene.P2M;
        _this._needDebug = false;
        return _this;
    }
    PhyScene.PhyLen = function (len) {
        return len / PhyScene.P2M;
    };
    PhyScene.EgretLen = function (len) {
        return len * PhyScene.P2M;
    };
    Object.defineProperty(PhyScene.prototype, "World", {
        get: function () {
            return this._world;
        },
        enumerable: true,
        configurable: true
    });
    PhyScene.prototype.initPhy = function (bg) {
        var gravity = new Box2D.Common.Math.b2Vec2(0, 4 * this._step / this._p2m);
        this._world = new Box2D.Dynamics.b2World(gravity, true);
        if (this._needDebug) {
            this._debug = new Box2D.Dynamics.b2DebugDraw();
            var s = new egret.Sprite();
            this._debug.SetSprite(s);
            bg.addChild(s);
            this._debug.SetDrawScale(this._p2m);
            this._debug.SetLineThickness(1);
            this._debug.SetAlpha(0.8);
            this._debug.SetFillAlpha(0.5);
            this._debug.SetFlags(Box2D.Dynamics.b2DebugDraw.e_shapeBit | Box2D.Dynamics.b2DebugDraw.e_jointBit);
            this._world.SetDebugDraw(this._debug);
        }
    };
    PhyScene.prototype.phyLoop = function () {
        this._world.Step(1 / this._step, 3, 6);
        if (this._debug != null) {
            this._world.DrawDebugData();
        }
    };
    PhyScene.P2M = 10;
    return PhyScene;
}(core.BaseScene));
__reflect(PhyScene.prototype, "PhyScene");
var core;
(function (core) {
    var BaseClass = (function () {
        function BaseClass() {
        }
        //获取一个单例
        BaseClass.getInstance = function () {
            var args = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                args[_i] = arguments[_i];
            }
            var Class = this;
            if (!Class._instance) {
                var argsLen = args.length;
                if (argsLen == 0) {
                    Class._instance = new Class();
                }
                else if (argsLen == 1) {
                    Class._instance = new Class(args[0]);
                }
                else if (argsLen == 2) {
                    Class._instance = new Class(args[0], args[1]);
                }
                else if (argsLen == 3) {
                    Class._instance = new Class(args[0], args[1], args[2]);
                }
                else if (argsLen == 4) {
                    Class._instance = new Class(args[0], args[1], args[2], args[3]);
                }
                else if (argsLen == 5) {
                    Class._instance = new Class(args[0], args[1], args[2], args[3], args[4]);
                }
            }
            return Class._instance;
        };
        return BaseClass;
    }());
    core.BaseClass = BaseClass;
    __reflect(BaseClass.prototype, "core.BaseClass");
})(core || (core = {}));
var core;
(function (core) {
    var BaseController = (function () {
        function BaseController() {
            this._messages = {};
        }
        BaseController.prototype.registerFunc = function (key, callbackFunc, callbackObj) {
            this._messages[key] = [callbackFunc, callbackObj];
        };
        BaseController.prototype.applyFunc = function (key) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            var listen = this._messages[key];
            if (listen) {
                return listen[0].apply(listen[1], param);
            }
            else {
                console.debug("消息" + key + "不存在侦听");
                return null;
            }
        };
        BaseController.prototype.setModel = function (model) {
            this._model = model;
        };
        BaseController.prototype.getModel = function () {
            return this._model;
        };
        BaseController.prototype.getControllerModel = function (controllerD) {
            return core.App.ControllerManager.getControllerModel(controllerD);
        };
        BaseController.prototype.applyControllerFunc = function (controllerKey, key) {
            var param = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                param[_i - 2] = arguments[_i];
            }
            return core.App.ControllerManager.applyFunc.apply(core.App.ControllerManager, arguments);
        };
        return BaseController;
    }());
    core.BaseController = BaseController;
    __reflect(BaseController.prototype, "core.BaseController");
})(core || (core = {}));
var core;
(function (core) {
    var BaseEuiView = (function (_super) {
        __extends(BaseEuiView, _super);
        function BaseEuiView(controller, parent) {
            var _this = _super.call(this) || this;
            _this._resources = null;
            _this._controller = controller;
            _this._myParent = parent;
            _this._isInit = false;
            _this.percentHeight = 100;
            _this.percentWidth = 100;
            return _this;
        }
        BaseEuiView.prototype.isShow = function () {
            return this.stage != null && this.visible;
        };
        BaseEuiView.prototype.addToParent = function () {
            this._myParent.addChild(this);
        };
        BaseEuiView.prototype.removeFromParent = function () {
            core.App.DisplayUtils.removeFromParent(this);
        };
        BaseEuiView.prototype.loadResource = function (loadComplete, initComplete) {
            if (this._resources && this._resources.length > 0) {
                core.App.ResourceUtils.loadResource(this._resources, [], loadComplete, null, this);
                this.once(eui.UIEvent.CREATION_COMPLETE, initComplete, this);
            }
            else {
                loadComplete();
                initComplete();
            }
        };
        BaseEuiView.prototype.setVisible = function (value) {
            this.visible = value;
        };
        Object.defineProperty(BaseEuiView.prototype, "myParent", {
            get: function () {
                return this._myParent;
            },
            enumerable: true,
            configurable: true
        });
        BaseEuiView.prototype.setResources = function (resources) {
            this._resources = resources;
        };
        BaseEuiView.prototype.isInit = function () {
            return this._isInit;
        };
        BaseEuiView.prototype.applyFunc = function (key) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            return this._controller.applyFunc.apply(this._controller, arguments);
        };
        BaseEuiView.prototype.applyControllerFunc = function (controllerKey, key) {
            var param = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                param[_i - 2] = arguments[_i];
            }
            return this._controller.applyControllerFunc.apply(this._controller, arguments);
        };
        BaseEuiView.prototype.initUI = function () {
            this._isInit = true;
        };
        BaseEuiView.prototype.initData = function () {
        };
        BaseEuiView.prototype.destroy = function () {
            this._controller = null;
            this._myParent = null;
            this._resources = null;
        };
        BaseEuiView.prototype.open = function () {
            var param = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                param[_i] = arguments[_i];
            }
        };
        BaseEuiView.prototype.close = function () {
            var param = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                param[_i] = arguments[_i];
            }
        };
        return BaseEuiView;
    }(eui.Component));
    core.BaseEuiView = BaseEuiView;
    __reflect(BaseEuiView.prototype, "core.BaseEuiView", ["core.IBaseView"]);
})(core || (core = {}));
var core;
(function (core) {
    var BaseEuiLayer = (function (_super) {
        __extends(BaseEuiLayer, _super);
        function BaseEuiLayer() {
            var _this = _super.call(this) || this;
            _this.percentWidth = 100;
            _this.percentHeight = 100;
            _this.touchEnabled = false;
            return _this;
        }
        return BaseEuiLayer;
    }(eui.Group));
    core.BaseEuiLayer = BaseEuiLayer;
    __reflect(BaseEuiLayer.prototype, "core.BaseEuiLayer");
})(core || (core = {}));
var core;
(function (core) {
    var BaseSpriteLayer = (function (_super) {
        __extends(BaseSpriteLayer, _super);
        function BaseSpriteLayer() {
            var _this = _super.call(this) || this;
            _this.touchEnabled = false;
            return _this;
        }
        return BaseSpriteLayer;
    }(egret.DisplayObjectContainer));
    core.BaseSpriteLayer = BaseSpriteLayer;
    __reflect(BaseSpriteLayer.prototype, "core.BaseSpriteLayer");
})(core || (core = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var AssetAdapter = (function () {
    function AssetAdapter() {
    }
    /**
     * @language zh_CN
     * 解析素材
     * @param source 待解析的新素材标识符
     * @param compFunc 解析完成回调函数，示例：callBack(content:any,source:string):void;
     * @param thisObject callBack的 this 引用
     */
    AssetAdapter.prototype.getAsset = function (source, compFunc, thisObject) {
        function onGetRes(data) {
            compFunc.call(thisObject, data, source);
        }
        if (RES.hasRes(source)) {
            var data = RES.getRes(source);
            if (data) {
                onGetRes(data);
            }
            else {
                RES.getResAsync(source, onGetRes, this);
            }
        }
        else {
            RES.getResByUrl(source, onGetRes, this, RES.ResourceItem.TYPE_IMAGE);
        }
    };
    return AssetAdapter;
}());
__reflect(AssetAdapter.prototype, "AssetAdapter", ["eui.IAssetAdapter"]);
var EnterScene = (function (_super) {
    __extends(EnterScene, _super);
    function EnterScene() {
        return _super.call(this) || this;
    }
    EnterScene.prototype.onEnter = function () {
        _super.prototype.onEnter.call(this);
        this.addLayer(LayerManager.UI_Game);
        core.App.ViewManager.open(ui.ViewConst.StartGame);
        //LayerManager.UI_Game.addChild(new ui.TestUI())
    };
    return EnterScene;
}(core.BaseScene));
__reflect(EnterScene.prototype, "EnterScene");
var StartGameControl = (function (_super) {
    __extends(StartGameControl, _super);
    function StartGameControl() {
        var _this = _super.call(this) || this;
        _this._view = new ui.StartGame(_this, LayerManager.UI_Game);
        _this.registerFunc(ui.StartGameEvent.StartGameBtn, _this.onStartGameBtn, _this);
        return _this;
    }
    StartGameControl.Init = function () {
        if (StartGameControl.hasInited) {
            return;
        }
        StartGameControl.hasInited = true;
        core.App.ControllerManager.register(ControllerConsts.StartGame, new StartGameControl());
    };
    StartGameControl.prototype.onStartGameBtn = function () {
        core.App.SceneManager.runScene(SceneConsts.Tarzan);
    };
    StartGameControl.hasInited = false;
    return StartGameControl;
}(core.BaseController));
__reflect(StartGameControl.prototype, "StartGameControl");
var TarzanContactListener = (function (_super) {
    __extends(TarzanContactListener, _super);
    function TarzanContactListener(scene) {
        var _this = _super.call(this) || this;
        _this._scene = scene;
        return _this;
    }
    TarzanContactListener.prototype.BeginContact = function (contact) {
        var fixA = contact.GetFixtureA().GetBody().GetUserData();
        var fixB = contact.GetFixtureB().GetBody().GetUserData();
        if (fixA.Type == PhyObjectType.Player && fixB.Type == PhyObjectType.Terrian) {
            this.playContractTrrain(contact.GetFixtureA(), contact.GetFixtureB());
        }
        else if (fixA.Type == PhyObjectType.Terrian && fixB.Type == PhyObjectType.Player) {
            this.playContractTrrain(contact.GetFixtureB(), contact.GetFixtureA());
        }
    };
    TarzanContactListener.prototype.EndContact = function (contact) {
    };
    TarzanContactListener.prototype.PostSolve = function (contact, impulse) {
    };
    TarzanContactListener.prototype.PreSolve = function (contact, oldManifold) {
    };
    TarzanContactListener.prototype.playContractTrrain = function (fixP, fixT) {
        var player = fixP.GetBody().GetUserData();
        var trrain = fixT.GetBody().GetUserData();
        this._scene.GameOver();
    };
    return TarzanContactListener;
}(Box2D.Dynamics.b2ContactListener));
__reflect(TarzanContactListener.prototype, "TarzanContactListener");
var PhyObjectType;
(function (PhyObjectType) {
    PhyObjectType[PhyObjectType["Player"] = 1] = "Player";
    PhyObjectType[PhyObjectType["Terrian"] = 2] = "Terrian";
    PhyObjectType[PhyObjectType["Role"] = 3] = "Role";
})(PhyObjectType || (PhyObjectType = {}));
var PhyObject = (function () {
    function PhyObject(type, container) {
        this._type = type;
        this._container = container;
    }
    Object.defineProperty(PhyObject.prototype, "Type", {
        get: function () {
            return this._type;
        },
        enumerable: true,
        configurable: true
    });
    return PhyObject;
}());
__reflect(PhyObject.prototype, "PhyObject");
//====================================================
var TerrianPhyObject = (function (_super) {
    __extends(TerrianPhyObject, _super);
    function TerrianPhyObject(container, world, width, height, x, y, p) {
        var _this = _super.call(this, PhyObjectType.Terrian, container) || this;
        _this._bmp = new egret.Bitmap;
        _this._bmp.texture = RES.getRes("stone_png");
        _this._container.addChild(_this._bmp);
        {
            var bodyDef = new Box2D.Dynamics.b2BodyDef();
            bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
            bodyDef.bullet = true;
            bodyDef.linearDamping = 0.1;
            bodyDef.angularDamping = 0.2;
            bodyDef.fixedRotation = false;
            bodyDef.allowSleep = true;
            bodyDef.position.x = x;
            bodyDef.position.y = y;
            bodyDef.angle = Math.PI / 2;
            var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
            fixtureDef.density = 1;
            fixtureDef.friction = 0;
            fixtureDef.restitution = 0.8;
            _this.body = world.CreateBody(bodyDef);
            _this.body.SetUserData(_this);
            {
                var shape = new Box2D.Collision.Shapes.b2PolygonShape();
                shape.SetAsBox(PhyScene.PhyLen(width) / 2, PhyScene.PhyLen(height) / 2);
                fixtureDef.shape = shape;
                _this.body.CreateFixture(fixtureDef);
            }
            {
                var shape = new Box2D.Collision.Shapes.b2CircleShape();
                shape.SetRadius(PhyScene.PhyLen(5));
                shape.SetLocalPosition((new Box2D.Common.Math.b2Vec2(-p * PhyScene.PhyLen(width / 2 - 10), 0)));
                fixtureDef.shape = shape;
                _this.body.CreateFixture(fixtureDef);
                _this._arch = shape.GetLocalPosition();
                _this._arch = _this.body.GetWorldPoint(shape.GetLocalPosition());
            }
        }
        _this._bmp.width = height;
        _this._bmp.height = width;
        _this._bmp.anchorOffsetX = _this._bmp.width / 2;
        _this._bmp.anchorOffsetY = _this._bmp.height / 2;
        _this._bmp.x = PhyScene.EgretLen(x);
        _this._bmp.y = PhyScene.EgretLen(y);
        return _this;
    }
    Object.defineProperty(TerrianPhyObject.prototype, "Arch", {
        get: function () {
            return this._arch;
        },
        enumerable: true,
        configurable: true
    });
    TerrianPhyObject.prototype.RefreshBox = function (width, height) {
        var pos = this.body.GetPosition();
        this._bmp.width = width;
        this._bmp.height = height;
        this._bmp.anchorOffsetX = this._bmp.width / 2;
        this._bmp.anchorOffsetY = this._bmp.height / 2;
        this._bmp.x = PhyScene.EgretLen(pos.x);
        this._bmp.y = PhyScene.EgretLen(pos.y);
    };
    TerrianPhyObject.prototype.Release = function () {
        this._container.removeChild(this._bmp);
    };
    return TerrianPhyObject;
}(PhyObject));
__reflect(TerrianPhyObject.prototype, "TerrianPhyObject");
//====================================================
var PlayerPhyObject = (function (_super) {
    __extends(PlayerPhyObject, _super);
    function PlayerPhyObject(container, world, size) {
        var _this = _super.call(this, PhyObjectType.Player, container) || this;
        _this._bmp = new egret.Bitmap;
        _this._bmp.texture = RES.getRes("player_png");
        _this._container.addChild(_this._bmp);
        {
            var bodyDef = new Box2D.Dynamics.b2BodyDef();
            bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
            bodyDef.bullet = true;
            bodyDef.linearDamping = 0;
            bodyDef.angularDamping = 0;
            bodyDef.fixedRotation = false;
            bodyDef.allowSleep = true;
            bodyDef.position.x = 0;
            bodyDef.position.y = 0; //App.StageUtils.getHeight() / 2 / this._p2m
            bodyDef.angle = Math.PI / 2;
            var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
            fixtureDef.density = 1;
            fixtureDef.friction = 0;
            fixtureDef.restitution = 0.8;
            _this.body = world.CreateBody(bodyDef);
            _this.body.ApplyImpulse(new Box2D.Common.Math.b2Vec2(8, 0), _this.body.GetPosition());
            _this.body.SetUserData(_this);
            _this.RefreshPos();
            {
                var shape = new Box2D.Collision.Shapes.b2CircleShape();
                shape.SetRadius(PhyScene.PhyLen(size));
                fixtureDef.shape = shape;
                _this.body.CreateFixture(fixtureDef);
            }
        }
        _this._bmp.width = size * 2;
        _this._bmp.height = size * 2;
        _this._bmp.anchorOffsetX = _this._bmp.width / 2;
        _this._bmp.anchorOffsetY = _this._bmp.height / 2;
        return _this;
    }
    PlayerPhyObject.prototype.RefreshPos = function () {
        var pos = this.body.GetPosition();
        this._bmp.x = PhyScene.EgretLen(pos.x);
        this._bmp.y = PhyScene.EgretLen(pos.y);
        var v = this.body.GetLinearVelocity();
        console.log("GetLinearVelocity: " + v.x + "," + v.y);
        if (v.x > 10) {
            v.x = v.x - 0.2;
        }
        this.body.SetLinearVelocity(v);
    };
    PlayerPhyObject.prototype.Release = function () {
        this._container.removeChild(this._bmp);
    };
    return PlayerPhyObject;
}(PhyObject));
__reflect(PlayerPhyObject.prototype, "PlayerPhyObject");
//====================================================
var RolePhyObject = (function (_super) {
    __extends(RolePhyObject, _super);
    function RolePhyObject(container, world, player, terrian) {
        var _this = _super.call(this, PhyObjectType.Role, container) || this;
        _this._bmp = null;
        _this._world = world;
        var joinDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
        joinDef.Initialize(terrian.body, player.body, terrian.Arch);
        joinDef.enableMotor = true;
        joinDef.enableLimit = false;
        joinDef.collideConnected = false;
        joinDef.motorSpeed = -100;
        joinDef.maxMotorTorque = 1800;
        _this._joint = _this._world.CreateJoint(joinDef);
        _this._bmp = new egret.Bitmap;
        _this._bmp.texture = RES.getRes("player_png");
        _this._container.addChild(_this._bmp);
        var pos1 = _this._joint.GetAnchorA();
        var pos2 = _this._joint.GetBodyB().GetPosition();
        var length = Math.sqrt(Math.pow(pos1.x - pos2.x, 2) + Math.pow(pos1.y - pos2.y, 2));
        _this._bmp.width = 5;
        _this._bmp.height = PhyScene.EgretLen(length);
        _this._bmp.x = PhyScene.EgretLen(pos1.x);
        _this._bmp.y = PhyScene.EgretLen(pos1.y);
        //this._bmp.skewX = (pos1.y - pos2.y)/ (pos1.x - pos2.x)
        _this.RefreshPos();
        return _this;
    }
    Object.defineProperty(RolePhyObject.prototype, "Joint", {
        get: function () {
            return this._joint;
        },
        enumerable: true,
        configurable: true
    });
    RolePhyObject.prototype.RefreshPos = function () {
        if (this._bmp != null) {
            var pos1 = this._joint.GetAnchorA();
            var pos2 = this._joint.GetBodyB().GetPosition();
            var pos = pos2;
            pos.x = pos2.x - pos1.x;
            pos.y = pos2.y - pos1.y;
            var angle = Math.atan2(pos.y, pos.x); // - Math.atan2(pos1.y, pos1.x)
            angle = (angle / Math.PI * 180) - 90;
            //console.log("angle: " + pos.x + "," + pos.y)
            console.log("angle: " + angle);
            this._bmp.rotation = angle;
        }
    };
    RolePhyObject.prototype.Release = function () {
        if (this._joint != null) {
            this._world.DestroyJoint(this._joint);
        }
        if (this._bmp != null) {
            this._container.removeChild(this._bmp);
            this._bmp = null;
        }
    };
    return RolePhyObject;
}(PhyObject));
__reflect(RolePhyObject.prototype, "RolePhyObject");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var LoadingUI = (function (_super) {
    __extends(LoadingUI, _super);
    function LoadingUI() {
        var _this = _super.call(this) || this;
        _this.background = new egret.Bitmap();
        _this.createView();
        return _this;
    }
    LoadingUI.prototype.createView = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                //await this.loadBackground();
                this.textField = new egret.TextField();
                this.addChild(this.textField);
                this.textField.y = 300;
                this.textField.width = 480;
                this.textField.height = 100;
                this.textField.textAlign = "center";
                this.textField.text = "loading......................";
                return [2 /*return*/];
            });
        });
    };
    LoadingUI.prototype.onProgress = function (current, total) {
        this.textField.text = "Loading..." + current + "/" + total;
    };
    LoadingUI.prototype.loadBackground = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve, reject) {
                        _this.urlloader = new egret.URLLoader();
                        _this.urlloader.dataFormat = egret.URLLoaderDataFormat.TEXTURE;
                        var urlreq = new egret.URLRequest();
                        urlreq.url = "/resource/assets/loading_background.png";
                        _this.urlloader.load(urlreq);
                        _this.urlloader.addEventListener(egret.Event.COMPLETE, function (event) {
                            var img = new egret.Bitmap((_this.urlloader.data));
                            _this.addChild(img);
                            resolve();
                        }, _this);
                    })];
            });
        });
    };
    return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI", ["RES.PromiseTaskReporter"]);
var TerrienData = (function () {
    function TerrienData() {
    }
    TerrienData.prototype.Destroy = function (parent) {
        if (this.obj != null && this.obj.body != null) {
            parent.World.DestroyBody(this.obj.body);
            this.obj.body = null;
        }
        this.obj.Release();
    };
    return TerrienData;
}());
__reflect(TerrienData.prototype, "TerrienData");
var Terrien = (function () {
    function Terrien() {
    }
    Terrien.prototype.Destroy = function (parent) {
        if (this.up != null) {
            this.up.Destroy(parent);
            this.up = null;
        }
        if (this.down != null) {
            this.down.Destroy(parent);
            this.down = null;
        }
    };
    return Terrien;
}());
__reflect(Terrien.prototype, "Terrien");
var RandomTerrien = (function () {
    function RandomTerrien(scene, player) {
        this._fromIndex = 0;
        this._toIndex = 0;
        this._terrien = null;
        this._inited = false;
        this._realIndex = 0;
        this._curIndex = 0;
        this._maxLength = 2 * core.App.StageUtils.getWidth();
        this._tall = core.App.StageUtils.getHeight();
        this._spaceRate = 0.3;
        this._cellWidth = 60;
        this._zoomHeight = 200;
        this._cellCount = Math.ceil(this._maxLength / this._cellWidth / 2) * 2;
        this._curIndex = -this._cellCount / 2;
        this._phyScene = scene;
        this._Player = player;
        this._terrien = new Array(this._cellCount);
        console.log("RandomTerrien:  " + this._maxLength + "," + this._tall);
    }
    Object.defineProperty(RandomTerrien.prototype, "World", {
        get: function () {
            return this._phyScene.World;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RandomTerrien.prototype, "Player", {
        get: function () {
            return this._Player;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RandomTerrien.prototype, "Backgroud", {
        get: function () {
            return this._phyScene.Background;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RandomTerrien.prototype, "Score", {
        get: function () {
            return this._realIndex;
        },
        enumerable: true,
        configurable: true
    });
    RandomTerrien.prototype.LookAt = function (x, y) {
        this.RandomData(x);
    };
    RandomTerrien.prototype.RandomData = function (index) {
        this._realIndex = Math.ceil(index / this._cellWidth);
        index = this._realIndex + this._cellCount / 2;
        if (this._inited && this._curIndex == index) {
            return;
        }
        console.log("RandomData:" + index);
        for (var n = this._curIndex; n < index; n++) {
            var i = n % this._cellCount;
            if (i < 0) {
                i = i + this._cellCount;
            }
            if (this._terrien[i] == null) {
                this._terrien[i] = new Terrien();
            }
            else {
                this._terrien[i].Destroy(this);
            }
            this._terrien[i].index = n;
            this._terrien[i].up = new TerrienData();
            this._terrien[i].up.index = n;
            this._terrien[i].up.height = this._zoomHeight + Math.ceil(Math.random() * (this._tall * (1 - this._spaceRate))) / 2;
            if (n < 10) {
                this._terrien[i].up.height = this._zoomHeight + this._tall / 6;
            }
            this._terrien[i].down = new TerrienData();
            this._terrien[i].down.index = n;
            this._terrien[i].down.height = this._zoomHeight + Math.ceil(Math.random() * (this._tall * (1 - this._spaceRate))) / 2;
            if (n < 10) {
                this._terrien[i].down.height = this._zoomHeight + this._tall / 4;
            }
            {
                {
                    var t = this._terrien[i].up;
                    var p = 1;
                    var x = PhyScene.PhyLen(n * this._cellWidth);
                    var y = p * PhyScene.PhyLen(this._zoomHeight + this._tall / 2 - t.height / 2);
                    var width = t.height;
                    var height = this._cellWidth;
                    t.obj = new TerrianPhyObject(this.Backgroud, this.World, width, height, x, y, p);
                }
                {
                    var t = this._terrien[i].down;
                    var p = -1;
                    var x = PhyScene.PhyLen(n * this._cellWidth);
                    var y = p * PhyScene.PhyLen(this._zoomHeight + this._tall / 2 - t.height / 2);
                    var width = t.height;
                    var height = this._cellWidth;
                    t.obj = new TerrianPhyObject(this.Backgroud, this.World, width, height, x, y, p);
                }
            }
        }
        this._curIndex = index;
        this._inited = true;
        /*
        if (this._inited && index > this._fromIndex + this._maxLength / 4 && index < this._toIndex - this._maxLength / 4) {
            return
        }
        
        this._fromIndex = index - this._maxLength / 2
        this._toIndex = index + this._maxLength / 2
        */
    };
    RandomTerrien.prototype.onTap = function () {
        var i = (this._realIndex + 2) % this._cellCount;
        var t = this._terrien[i];
        console.log("Destroy:  " + t);
        //t.Destroy(this)
    };
    RandomTerrien.prototype.makeTheRole = function () {
        this.releaseTheRole();
        var i = (this._realIndex + 1) % this._cellCount;
        var t = this._terrien[i];
        if (this._flySound == null) {
            this._flySound = RES.getRes("fly_mp3");
        }
        this._flySound.play(0, 1);
        this.Role = new RolePhyObject(this.Backgroud, this.World, this.Player, t.down.obj);
    };
    RandomTerrien.prototype.releaseTheRole = function () {
        if (this.Role != null) {
            this.Role.Release();
        }
    };
    RandomTerrien.prototype.Refresh = function () {
        if (this.Role != null) {
            this.Role.RefreshPos();
        }
    };
    return RandomTerrien;
}());
__reflect(RandomTerrien.prototype, "RandomTerrien");
var TarzanScene = (function (_super) {
    __extends(TarzanScene, _super);
    function TarzanScene() {
        var _this = _super.call(this) || this;
        _this._lookAtX = 0;
        _this._lookAtY = 0;
        _this._score = 0;
        //private _ball: Box2D.Dynamics.b2Body = null
        _this._ball = null;
        _this._randomMap = null;
        return _this;
    }
    Object.defineProperty(TarzanScene.prototype, "Background", {
        get: function () {
            return this._bg;
        },
        enumerable: true,
        configurable: true
    });
    TarzanScene.prototype.init = function () {
        this._gameOver = false;
        this._lookAtX = 0;
        this._lookAtY = 0;
        console.log("TarzanScene.init" + core.App.StageUtils.getHeight() + " " + core.App.StageUtils.getWidth());
        this._bg = new TitleMap();
        this._bg.initMap();
        LayerManager.Game_Bg.addChild(this._bg);
        this._bg.LookAt(0, 0);
        this.initPhy(this._bg);
        this._ball = new PlayerPhyObject(this.Background, this.World, 15);
        this._randomMap = new RandomTerrien(this, this._ball);
        this.World.SetContactListener(new TarzanContactListener(this));
        {
            /*
            let bodyDef = new Box2D.Dynamics.b2BodyDef()
            bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody
            bodyDef.bullet = true
            bodyDef.linearDamping = 0
            bodyDef.angularDamping = 0
            bodyDef.fixedRotation = false
            bodyDef.allowSleep = true
            bodyDef.position.x = this.PhyLen(-50)
            bodyDef.position.y = this.PhyLen(10) //App.StageUtils.getHeight() / 2 / this._p2m
            bodyDef.angle = Math.PI / 2
            let fixtureDef = new Box2D.Dynamics.b2FixtureDef()
            fixtureDef.density = 1
            fixtureDef.friction = 0
            fixtureDef.restitution = 0.8

            let stone = this._world.CreateBody(bodyDef)
            {
                let shape = new Box2D.Collision.Shapes.b2CircleShape()
                shape.SetRadius(this.PhyLen(20))
                fixtureDef.shape = shape
                stone.CreateFixture(fixtureDef)
            }
            */
            /*
            let joinDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef()
            joinDef.Initialize(stone, this._ball, stone.GetPosition())
            joinDef.enableMotor = true
            this._world.CreateJoint(joinDef)
            */
        }
    };
    TarzanScene.prototype.lookAt = function (x, y) {
        this._bg.LookAt(x, y);
        this._randomMap.LookAt(x, y);
        if (this._oldScore != this._randomMap.Score) {
            this._oldScore = this._randomMap.Score;
            core.App.ControllerManager.applyFunc(ControllerConsts.MainGame, MainGameControlEvent.SetScore, this._oldScore);
        }
    };
    TarzanScene.prototype.onTap = function (e) {
        console.log("onTap");
        this._randomMap.onTap();
    };
    TarzanScene.prototype.onTapBegin = function (e) {
        if (this._gameOver == false) {
            this._randomMap.makeTheRole();
        }
    };
    TarzanScene.prototype.onTapEnd = function (e) {
        this._randomMap.releaseTheRole();
    };
    TarzanScene.prototype.GameOver = function () {
        console.log("GameOver==========================");
        if (this._gameOver == false) {
            this._gameOver = true;
            //core.App.ViewManager.open(ui.ViewConst.GameOver)
            if (this._boom_sound == null) {
                this._boom_sound = RES.getRes("boom_mp3");
                this._boom_sound.type = egret.Sound.EFFECT;
            }
            this._boom_sound.play(0, 1);
            this._backSoundChannel.stop();
            core.App.ControllerManager.applyFunc(ControllerConsts.GameOver, GameOverControlEvent.GameIsOver, this._randomMap.Score);
        }
    };
    TarzanScene.prototype.onEnter = function () {
        _super.prototype.onEnter.call(this);
        this.init();
        this.addLayerAt(LayerManager.Game_Bg, 0);
        this.addLayerAt(LayerManager.UI_Game, 1);
        //core.App.ViewManager.open(ui.ViewConst.GameOver)
        core.App.ViewManager.open(ui.ViewConst.MainGame);
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTapBegin, this);
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_END, this.onTapEnd, this);
        LayerManager.UI_Game.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.onTapEnd, this);
        LayerManager.UI_Game.touchEnabled = true;
        this._backSound = RES.getRes("back_mp3");
        this._backSoundChannel = this._backSound.play();
        this._backSound.type = egret.Sound.MUSIC;
    };
    TarzanScene.prototype.enterFrame = function (time) {
        if (this._gameOver) {
            return;
        }
        this.phyLoop();
        if (this._ball != null) {
            var pos = this._ball.body.GetPosition();
            this.lookAt(PhyScene.EgretLen(pos.x), PhyScene.EgretLen(pos.y));
            this._ball.RefreshPos();
        }
        if (this._randomMap != null) {
            this._randomMap.Refresh();
        }
    };
    return TarzanScene;
}(PhyScene));
__reflect(TarzanScene.prototype, "TarzanScene");
var GameOverControlEvent;
(function (GameOverControlEvent) {
    GameOverControlEvent[GameOverControlEvent["GameIsOver"] = 1] = "GameIsOver";
})(GameOverControlEvent || (GameOverControlEvent = {}));
var GameOverControl = (function (_super) {
    __extends(GameOverControl, _super);
    function GameOverControl() {
        var _this = _super.call(this) || this;
        _this._view = new ui.GameOver(_this, LayerManager.UI_Game);
        _this.registerFunc(ui.GameOverEvent.TryAgainBtn, _this.onTryAgain, _this);
        _this.registerFunc(GameOverControlEvent.GameIsOver, _this.showGameOver, _this);
        return _this;
    }
    GameOverControl.Init = function () {
        if (GameOverControl.hasInited) {
            return;
        }
        GameOverControl.hasInited = true;
        core.App.ControllerManager.register(ControllerConsts.GameOver, new GameOverControl());
    };
    GameOverControl.prototype.onTryAgain = function () {
        core.App.SceneManager.runScene(SceneConsts.Tarzan);
    };
    GameOverControl.prototype.showGameOver = function (score) {
        core.App.ViewManager.open(ui.ViewConst.GameOver);
        this._view.SetScoreLText(score.toString());
    };
    GameOverControl.hasInited = false;
    return GameOverControl;
}(core.BaseController));
__reflect(GameOverControl.prototype, "GameOverControl");
var MainGameControlEvent;
(function (MainGameControlEvent) {
    MainGameControlEvent[MainGameControlEvent["SetScore"] = 1] = "SetScore";
})(MainGameControlEvent || (MainGameControlEvent = {}));
var MainGameControl = (function (_super) {
    __extends(MainGameControl, _super);
    function MainGameControl() {
        var _this = _super.call(this) || this;
        _this._view = new ui.MainGame(_this, LayerManager.UI_Game);
        _this.registerFunc(MainGameControlEvent.SetScore, _this.onSetScore, _this);
        return _this;
    }
    MainGameControl.Init = function () {
        if (MainGameControl.hasInited) {
            return;
        }
        MainGameControl.hasInited = true;
        core.App.ControllerManager.register(ControllerConsts.MainGame, new MainGameControl());
    };
    MainGameControl.prototype.onSetScore = function (score) {
        this._view.SetScoreLText(score.toString());
    };
    MainGameControl.hasInited = false;
    return MainGameControl;
}(core.BaseController));
__reflect(MainGameControl.prototype, "MainGameControl");
var ui;
(function (ui) {
    var GameOverEvent;
    (function (GameOverEvent) {
        GameOverEvent[GameOverEvent["TryAgainBtn"] = 1000] = "TryAgainBtn";
    })(GameOverEvent = ui.GameOverEvent || (ui.GameOverEvent = {}));
    var GameOver = (function (_super) {
        __extends(GameOver, _super);
        function GameOver(controller, parent) {
            var _this = _super.call(this, controller, parent) || this;
            _this.addEventListener(eui.UIEvent.COMPLETE, _this.onComplete, _this);
            core.App.ViewManager.register(ui.ViewConst.GameOver, _this);
            return _this;
        }
        GameOver.prototype.partAdded = function (partName, instance) {
            _super.prototype.partAdded.call(this, partName, instance);
        };
        GameOver.prototype.childrenCreated = function () {
            _super.prototype.childrenCreated.call(this);
        };
        GameOver.prototype.onComplete = function (evt) {
            this.BaseGroup.x = 0;
            this.BaseGroup.y = 0;
            this.BaseGroup.anchorOffsetX = 0;
            this.BaseGroup.anchorOffsetY = 0;
            this.BaseGroup.width = egret.MainContext.instance.stage.stageWidth;
            this.BaseGroup.height = egret.MainContext.instance.stage.stageHeight;
            this.TryAgainBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTryAgainBtnTap, this);
            this.ScoreL.strokeColor = 0xE0A006;
            this.ScoreL.stroke = 2;
            this.NameL.strokeColor = 0xE0A006;
            this.NameL.stroke = 2;
        };
        GameOver.prototype.onTryAgainBtnTap = function (evt) {
            console.log("onTryAgainBtnTap");
            //core.App.SceneManager.runScene(SceneConsts.Tarzan);
            this.applyFunc(GameOverEvent.TryAgainBtn);
        };
        GameOver.prototype.SetScoreLText = function (text) {
            this.ScoreL.text = text;
        };
        return GameOver;
    }(core.BaseEuiView));
    ui.GameOver = GameOver;
    __reflect(GameOver.prototype, "ui.GameOver");
})(ui || (ui = {}));
var ui;
(function (ui) {
    var MainGame = (function (_super) {
        __extends(MainGame, _super);
        function MainGame(controller, parent) {
            var _this = _super.call(this, controller, parent) || this;
            _this.addEventListener(eui.UIEvent.COMPLETE, _this.onComplete, _this);
            core.App.ViewManager.register(ui.ViewConst.MainGame, _this);
            return _this;
        }
        MainGame.prototype.partAdded = function (partName, instance) {
            _super.prototype.partAdded.call(this, partName, instance);
        };
        MainGame.prototype.childrenCreated = function () {
            _super.prototype.childrenCreated.call(this);
        };
        MainGame.prototype.onComplete = function (evt) {
            this.BaseGroup.x = 0;
            this.BaseGroup.y = 0;
            this.BaseGroup.anchorOffsetX = 0;
            this.BaseGroup.anchorOffsetY = 0;
            this.BaseGroup.width = egret.MainContext.instance.stage.stageWidth;
            this.BaseGroup.height = egret.MainContext.instance.stage.stageHeight;
            this.ScoreL.text = "Score:0";
            this.ScoreL.strokeColor = 0xE0A006;
            this.ScoreL.stroke = 2;
        };
        MainGame.prototype.SetScoreLText = function (text) {
            this.ScoreL.text = "Score:" + text;
        };
        return MainGame;
    }(core.BaseEuiView));
    ui.MainGame = MainGame;
    __reflect(MainGame.prototype, "ui.MainGame");
})(ui || (ui = {}));
var ui;
(function (ui) {
    var StartGameEvent;
    (function (StartGameEvent) {
        StartGameEvent[StartGameEvent["StartGameBtn"] = 1000] = "StartGameBtn";
    })(StartGameEvent = ui.StartGameEvent || (ui.StartGameEvent = {}));
    var StartGame = (function (_super) {
        __extends(StartGame, _super);
        function StartGame(controller, parent) {
            var _this = _super.call(this, controller, parent) || this;
            _this.addEventListener(eui.UIEvent.COMPLETE, _this.onComplete, _this);
            core.App.ViewManager.register(ui.ViewConst.StartGame, _this);
            return _this;
        }
        StartGame.prototype.partAdded = function (partName, instance) {
            _super.prototype.partAdded.call(this, partName, instance);
        };
        StartGame.prototype.childrenCreated = function () {
            _super.prototype.childrenCreated.call(this);
        };
        StartGame.prototype.onComplete = function (evt) {
            this.BaseGroup.x = 0;
            this.BaseGroup.y = 0;
            this.BaseGroup.anchorOffsetX = 0;
            this.BaseGroup.anchorOffsetY = 0;
            this.BaseGroup.width = egret.MainContext.instance.stage.stageWidth;
            this.BaseGroup.height = egret.MainContext.instance.stage.stageHeight;
            this.StartBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onStartBtnTap, this);
        };
        StartGame.prototype.onStartBtnTap = function (evt) {
            console.log("onStartBtnTap");
            this.applyFunc(StartGameEvent.StartGameBtn);
        };
        return StartGame;
    }(core.BaseEuiView));
    ui.StartGame = StartGame;
    __reflect(StartGame.prototype, "ui.StartGame");
})(ui || (ui = {}));
var ui;
(function (ui) {
    var TestUI = (function (_super) {
        __extends(TestUI, _super);
        function TestUI() {
            return _super.call(this) || this;
        }
        TestUI.prototype.partAdded = function (partName, instance) {
            _super.prototype.partAdded.call(this, partName, instance);
        };
        TestUI.prototype.childrenCreated = function () {
            _super.prototype.childrenCreated.call(this);
        };
        return TestUI;
    }(eui.Component));
    ui.TestUI = TestUI;
    __reflect(TestUI.prototype, "ui.TestUI", ["eui.UIComponent", "egret.DisplayObject"]);
})(ui || (ui = {}));
var ui;
(function (ui) {
    var ViewConst;
    (function (ViewConst) {
        ViewConst[ViewConst["StartGame"] = 0] = "StartGame";
        ViewConst[ViewConst["GameOver"] = 1] = "GameOver";
        ViewConst[ViewConst["MainGame"] = 2] = "MainGame";
    })(ViewConst = ui.ViewConst || (ui.ViewConst = {}));
})(ui || (ui = {}));
var core;
(function (core) {
    var App = (function () {
        function App() {
        }
        Object.defineProperty(App, "StageUtils", {
            get: function () {
                return core.StageUtils.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "SceneManager", {
            get: function () {
                return core.SceneManager.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "ViewManager", {
            get: function () {
                return core.ViewManager.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "ControllerManager", {
            get: function () {
                return core.ControllerManager.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "TimerManager", {
            get: function () {
                return core.TimerManager.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "DebugUtils", {
            get: function () {
                return core.DebugUtils.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "EasyLoading", {
            get: function () {
                return core.EasyLoading.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "ResourceUtils", {
            get: function () {
                return core.ResourceUtils.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(App, "DisplayUtils", {
            get: function () {
                return core.DisplayUtils.getInstance();
            },
            enumerable: true,
            configurable: true
        });
        App.Init = function () {
            App.GlobalData = RES.getRes("global");
            App.DebugUtils.setOpen(App.GlobalData.IsDebug);
            console.debug(App.GlobalData);
        };
        App.GlobalData = null;
        return App;
    }());
    core.App = App;
    __reflect(App.prototype, "core.App");
})(core || (core = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var Main = (function (_super) {
    __extends(Main, _super);
    function Main() {
        var _this = _super.call(this) || this;
        _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
        return _this;
    }
    Main.prototype.onAddToStage = function (event) {
        egret.lifecycle.addLifecycleListener(function (context) {
            // custom lifecycle plugin
            context.onUpdate = function () {
            };
        });
        egret.lifecycle.onPause = function () {
            egret.ticker.pause();
        };
        egret.lifecycle.onResume = function () {
            egret.ticker.resume();
        };
        egret.registerImplementation("eui.IAssetAdapter", new AssetAdapter());
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
        this.runGame().catch(function (e) {
            console.log(e);
        });
    };
    Main.prototype.runGame = function () {
        return __awaiter(this, void 0, void 0, function () {
            var loadingView, app;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        loadingView = new LoadingUI();
                        this.stage.addChild(loadingView);
                        return [4 /*yield*/, RES.loadConfig("resource/default.res.json", "resource/")];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, RES.loadConfig("resource/default_ui.res.json", "resource/")];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, RES.loadConfig("resource/core.res.json", "resource/")];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, this.loadTheme()];
                    case 4:
                        _a.sent();
                        console.log("==============================================");
                        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
                        /*
                        core.App.ResourceUtils.loadGroup("default_ui", null, null, this)
                        core.App.ResourceUtils.loadGroup("game_preload", null, null, this)
                        core.App.ResourceUtils.loadGroup("preload", this.onResourceLoadComplete, this.onResourceLoadProgress, this)
                        */
                        return [4 /*yield*/, RES.loadGroup("preload", 0, loadingView)];
                    case 5:
                        /*
                        core.App.ResourceUtils.loadGroup("default_ui", null, null, this)
                        core.App.ResourceUtils.loadGroup("game_preload", null, null, this)
                        core.App.ResourceUtils.loadGroup("preload", this.onResourceLoadComplete, this.onResourceLoadProgress, this)
                        */
                        _a.sent();
                        return [4 /*yield*/, RES.loadGroup("default_ui", 0, loadingView)];
                    case 6:
                        _a.sent();
                        return [4 /*yield*/, RES.loadGroup("ui", 0, loadingView)];
                    case 7:
                        _a.sent();
                        this.stage.removeChild(loadingView);
                        app = new MyApp();
                        return [2 /*return*/];
                }
            });
        });
    };
    Main.prototype.loadTheme = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve, reject) {
                        // load skin theme configuration file, you can manually modify the file. And replace the default skin.
                        //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
                        var theme = new eui.Theme("resource/default.thm.json", _this.stage);
                        theme.addEventListener(eui.UIEvent.COMPLETE, function () {
                            resolve();
                        }, _this);
                    })];
            });
        });
    };
    Main.prototype.onConfigComplete = function () {
    };
    Main.prototype.onResourceLoadComplete = function (param1, param2) {
        var app = new MyApp();
    };
    Main.prototype.onResourceLoadProgress = function (itemsLoaded, itemsTotal) {
    };
    return Main;
}(egret.DisplayObjectContainer));
__reflect(Main.prototype, "Main");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var ThemeAdapter = (function () {
    function ThemeAdapter() {
    }
    ThemeAdapter.prototype.getTheme = function (url, onSuccess, onError, thisObject) {
        var _this = this;
        function onResGet(e) {
            onSuccess.call(thisObject, e);
        }
        function onResError(e) {
            if (e.resItem.url == url) {
                RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
                onError.call(thisObject);
            }
        }
        if (typeof generateEUI !== 'undefined') {
            egret.callLater(function () {
                onSuccess.call(thisObject, generateEUI);
            }, this);
        }
        else if (typeof generateEUI2 !== 'undefined') {
            RES.getResByUrl("resource/gameEui.json", function (data, url) {
                window["JSONParseClass"]["setData"](data);
                onResGet(data);
                egret.callLater(function () {
                    onSuccess.call(thisObject, generateEUI2);
                }, _this);
            }, this, RES.ResourceItem.TYPE_JSON);
        }
        else {
            RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
            RES.getResByUrl(url, onResGet, this, RES.ResourceItem.TYPE_TEXT);
        }
    };
    return ThemeAdapter;
}());
__reflect(ThemeAdapter.prototype, "ThemeAdapter", ["eui.IThemeAdapter"]);
var DebugPlatform = (function () {
    function DebugPlatform() {
    }
    DebugPlatform.prototype.getUserInfo = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { nickName: "username" }];
            });
        });
    };
    DebugPlatform.prototype.login = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
    window.platform = new DebugPlatform();
}
var core;
(function (core) {
    var EasyLoading = (function (_super) {
        __extends(EasyLoading, _super);
        function EasyLoading() {
            var _this = _super.call(this) || this;
            _this.init();
            return _this;
        }
        EasyLoading.prototype.init = function () {
            this.averageUtils = new core.AverageUtils();
            this.speed = 10 / (1000 / 60);
            this.content = new egret.Sprite();
            this.content.graphics.beginFill(0x000000, 0.2);
            this.content.graphics.drawRect(0, 0, core.App.StageUtils.getWidth(), core.App.StageUtils.getHeight());
            this.content.graphics.endFill();
            this.content.touchEnabled = true;
            this.uiImageContainer = new egret.DisplayObjectContainer();
            this.uiImageContainer.x = this.content.width * 0.5;
            this.uiImageContainer.y = this.content.height * 0.5;
            this.content.addChild(this.uiImageContainer);
            RES.getResByUrl("resource/assets/core/load_Reel.png", function (texture) {
                var img = new egret.Bitmap();
                img.texture = texture;
                img.x = -img.width * 0.5;
                img.y = -img.height * 0.5;
                this.uiImageContainer.addChild(img);
            }, this, RES.ResourceItem.TYPE_IMAGE);
        };
        EasyLoading.prototype.showLoading = function () {
            core.App.StageUtils.getStage().addChild(this.content);
            core.App.TimerManager.doFrame(1, 0, this.enterFrame, this);
        };
        EasyLoading.prototype.hideLoading = function () {
            if (this.content && this.content.parent) {
                core.App.StageUtils.getStage().removeChild(this.content);
                this.uiImageContainer.rotation = 0;
            }
            core.App.TimerManager.remove(this.enterFrame, this);
        };
        EasyLoading.prototype.enterFrame = function (time) {
            this.averageUtils.push(this.speed * time);
            this.uiImageContainer.rotation += this.averageUtils.getValue();
        };
        return EasyLoading;
    }(core.BaseClass));
    core.EasyLoading = EasyLoading;
    __reflect(EasyLoading.prototype, "core.EasyLoading");
})(core || (core = {}));
var core;
(function (core) {
    var ControllerManager = (function (_super) {
        __extends(ControllerManager, _super);
        function ControllerManager() {
            var _this = _super.call(this) || this;
            _this._modules = {};
            return _this;
        }
        ControllerManager.prototype.clear = function () {
            this._modules = {};
        };
        ControllerManager.prototype.register = function (key, control) {
            if (this.isExists(key))
                return;
            this._modules[key] = control;
        };
        ControllerManager.prototype.unregister = function (key) {
            if (!this.isExists(key))
                return;
            this._modules[key] = null;
            delete this._modules[key];
        };
        ControllerManager.prototype.isExists = function (key) {
            return this._modules[key] != null;
        };
        ControllerManager.prototype.applyFunc = function (controllerD, key) {
            var param = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                param[_i - 2] = arguments[_i];
            }
            var manager = this._modules[controllerD];
            if (manager) {
                //TODO: 这是什么意思，为啥不直接用param
                var params = [];
                for (var i = 1; i < arguments.length; i++) {
                    params[i - 1] = arguments[i];
                }
                return manager.applyFunc.apply(manager, params);
            }
            else {
                console.debug("模块" + controllerD + "不存在");
                return null;
            }
        };
        ControllerManager.prototype.getControllerModel = function (controllerD) {
            var manager = this._modules[controllerD];
            if (manager) {
                return manager.getModel();
            }
            return null;
        };
        return ControllerManager;
    }(core.BaseClass));
    core.ControllerManager = ControllerManager;
    __reflect(ControllerManager.prototype, "core.ControllerManager");
})(core || (core = {}));
var core;
(function (core) {
    var ViewManager = (function (_super) {
        __extends(ViewManager, _super);
        function ViewManager() {
            var _this = _super.call(this) || this;
            _this._views = {};
            _this._opens = new Array();
            return _this;
        }
        //注册View
        ViewManager.prototype.register = function (key, view) {
            if (view == null) {
                return;
            }
            if (this._views[key]) {
                console.debug("ViewManager register key重复" + key + view);
                return;
            }
            this._views[key] = view;
        };
        //注销View
        ViewManager.prototype.unregister = function (key) {
            if (!this._views[key]) {
                return;
            }
            this._views[key] = null;
            delete this._views[key];
        };
        //获取View
        ViewManager.prototype.getView = function (key) {
            return this._views[key];
        };
        ViewManager.prototype.isShow = function (key) {
            return this._opens.indexOf(key) != -1;
        };
        //销毁(或替换)View
        ViewManager.prototype.destroy = function (key, newView) {
            if (newView === void 0) { newView = null; }
            var oldView = this.getView(key);
            if (oldView) {
                this.unregister(key);
                oldView.destroy();
                oldView = null;
            }
            this.register(key, newView);
        };
        ViewManager.prototype.open = function (key) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            var view = this.getView(key);
            if (view == null) {
                console.error("UI_" + key + "不存在");
                return;
            }
            if (view.isShow()) {
                view.open.apply(view, param);
                return view;
            }
            if (view.isInit()) {
                view.addToParent();
                view.open.apply(view, param);
            }
            else {
                core.App.EasyLoading.showLoading();
                view.loadResource(function () {
                    view.setVisible(false);
                    view.addToParent();
                }.bind(this), function () {
                    view.initUI();
                    view.initData();
                    view.open.apply(view, param);
                    view.setVisible(true);
                    core.App.EasyLoading.hideLoading();
                }.bind(this));
            }
            this._opens.push(key);
            return view;
        };
        ViewManager.prototype.close = function (key) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            if (!this.isShow(key)) {
                return;
            }
            var view = this.getView(key);
            if (view == null) {
                return;
            }
            var viewIndex = this._opens.indexOf(key);
            if (key >= 0) {
                this._opens.splice(viewIndex, 1);
            }
            view.removeFromParent();
            view.close.apply(view, param);
        };
        ViewManager.prototype.closeView = function (view) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            var keys = Object.keys(this._views);
            for (var i = 0, len = keys.length; i < len; i++) {
                var key = parseInt(keys[i]);
                if (this._views[key] == view) {
                    this.close(key, param);
                    return;
                }
            }
        };
        ViewManager.prototype.closeAll = function () {
            while (this._opens.length) {
                this.close(this._opens[0]);
            }
        };
        return ViewManager;
    }(core.BaseClass));
    core.ViewManager = ViewManager;
    __reflect(ViewManager.prototype, "core.ViewManager");
})(core || (core = {}));
var MyApp = (function () {
    function MyApp() {
        console.log("Start MyApp");
        this.initModule();
        this.initScene();
        core.App.ResourceUtils.loadGroup("game_preload", this.onResourceLoadComplete, this.onResourceLoadProgress, this);
    }
    MyApp.prototype.initScene = function () {
        //App.SceneManager.register(SceneConsts.LOADING, new LoadingScene());
        //App.SceneManager.register(SceneConsts.GAME, new GameScene())
        //App.SceneManager.register(SceneConsts.TEST, new TestScene())
        //App.SceneManager.register(SceneConsts.FartMonkey, new FartMonkeyScene())
        core.App.SceneManager.register(SceneConsts.Tarzan, new TarzanScene());
        core.App.SceneManager.register(SceneConsts.Enter, new EnterScene());
    };
    MyApp.prototype.initModule = function () {
        //App.ControllerManager.register(ControllerConsts.GameMap, new GameMapController());
        StartGameControl.Init();
        GameOverControl.Init();
        MainGameControl.Init();
    };
    MyApp.prototype.onResourceLoadComplete = function (param1, param2) {
        console.log("onResourceLoadComplete");
        core.App.SceneManager.runScene(SceneConsts.Enter);
    };
    MyApp.prototype.onResourceLoadProgress = function (itemsLoaded, itemsTotal) {
        //App.ControllerManager.applyFunc(ControllerConsts.Loading, LoadingConst.SetProgress, itemsLoaded, itemsTotal);
        console.log("onResourceLoadProgress:" + itemsLoaded + "/" + itemsTotal);
    };
    return MyApp;
}());
__reflect(MyApp.prototype, "MyApp");
var core;
(function (core) {
    var BaseModel = (function () {
        function BaseModel($controller) {
            this._controller = $controller;
            this._controller.setModel(this);
        }
        return BaseModel;
    }());
    core.BaseModel = BaseModel;
    __reflect(BaseModel.prototype, "core.BaseModel");
})(core || (core = {}));
var ControllerConsts;
(function (ControllerConsts) {
    ControllerConsts[ControllerConsts["Loading"] = 0] = "Loading";
    ControllerConsts[ControllerConsts["GameMap"] = 1] = "GameMap";
    ControllerConsts[ControllerConsts["StartGame"] = 2] = "StartGame";
    ControllerConsts[ControllerConsts["GameOver"] = 3] = "GameOver";
    ControllerConsts[ControllerConsts["MainGame"] = 4] = "MainGame";
})(ControllerConsts || (ControllerConsts = {}));
var core;
(function (core) {
    var BaseSpriteView = (function (_super) {
        __extends(BaseSpriteView, _super);
        function BaseSpriteView(controller, parent) {
            var _this = _super.call(this) || this;
            _this._resources = null;
            _this._controller = controller;
            _this._myParent = parent;
            _this._isInit = false;
            core.App.StageUtils.getStage().addEventListener(egret.Event.RESIZE, _this.onResize, _this);
            return _this;
        }
        BaseSpriteView.prototype.onResize = function () {
        };
        BaseSpriteView.prototype.isShow = function () {
            return this.stage != null && this.visible;
        };
        BaseSpriteView.prototype.addToParent = function () {
            this._myParent.addChild(this);
        };
        BaseSpriteView.prototype.removeFromParent = function () {
            core.App.DisplayUtils.removeFromParent(this);
        };
        BaseSpriteView.prototype.loadResource = function (loadComplete, initComplete) {
            if (this._resources && this._resources.length > 0) {
                core.App.ResourceUtils.loadResource(this._resources, [], loadComplete, null, this);
                this.once(eui.UIEvent.CREATION_COMPLETE, initComplete, this);
            }
            else {
                loadComplete();
                initComplete();
            }
        };
        BaseSpriteView.prototype.setVisible = function (value) {
            this.visible = value;
        };
        Object.defineProperty(BaseSpriteView.prototype, "myParent", {
            get: function () {
                return this._myParent;
            },
            enumerable: true,
            configurable: true
        });
        BaseSpriteView.prototype.setResources = function (resources) {
            this._resources = resources;
        };
        BaseSpriteView.prototype.isInit = function () {
            return this._isInit;
        };
        BaseSpriteView.prototype.applyFunc = function (key) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            return this._controller.applyFunc.apply(this._controller, arguments);
        };
        BaseSpriteView.prototype.applyControllerFunc = function (controllerKey, key) {
            var param = [];
            for (var _i = 2; _i < arguments.length; _i++) {
                param[_i - 2] = arguments[_i];
            }
            return this._controller.applyControllerFunc.apply(this._controller, arguments);
        };
        BaseSpriteView.prototype.initUI = function () {
            this._isInit = true;
        };
        BaseSpriteView.prototype.initData = function () {
        };
        BaseSpriteView.prototype.destroy = function () {
            this._controller = null;
            this._myParent = null;
            this._resources = null;
        };
        BaseSpriteView.prototype.open = function () {
            var param = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                param[_i] = arguments[_i];
            }
        };
        BaseSpriteView.prototype.close = function () {
            var param = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                param[_i] = arguments[_i];
            }
        };
        return BaseSpriteView;
    }(egret.DisplayObjectContainer));
    core.BaseSpriteView = BaseSpriteView;
    __reflect(BaseSpriteView.prototype, "core.BaseSpriteView", ["core.IBaseView"]);
})(core || (core = {}));
var core;
(function (core) {
    var SceneManager = (function (_super) {
        __extends(SceneManager, _super);
        function SceneManager() {
            var _this = _super.call(this) || this;
            _this._scenes = {};
            core.App.TimerManager.doFrame(1, 0, _this.enterFrame, _this);
            return _this;
        }
        SceneManager.prototype.enterFrame = function (time) {
            var scene = this._scenes[this._currScene];
            if (scene) {
                scene.enterFrame(time);
            }
        };
        //清除所有的scene
        SceneManager.prototype.clear = function () {
            var nowScene = this._scenes[this._currScene];
            if (nowScene) {
                nowScene.onExit();
                this._currScene = undefined;
            }
            this._scenes = {};
        };
        //注册一个scene
        SceneManager.prototype.register = function (key, scene) {
            this._scenes[key] = scene;
        };
        //切换场景
        SceneManager.prototype.runScene = function (key) {
            var param = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                param[_i - 1] = arguments[_i];
            }
            var nowScene = this._scenes[key];
            if (nowScene == null) {
                console.debug("场景" + key + "不存在");
                return;
            }
            var oldScene = this._scenes[this._currScene];
            if (oldScene) {
                oldScene.onExit();
            }
            //TODO: 这个是啥语法?
            nowScene.onEnter.apply(nowScene, param);
            this._currScene = key;
        };
        //获取当前Scene
        SceneManager.prototype.getCurrScene = function () {
            return this._currScene;
        };
        return SceneManager;
    }(core.BaseClass));
    core.SceneManager = SceneManager;
    __reflect(SceneManager.prototype, "core.SceneManager");
})(core || (core = {}));
var SceneConsts;
(function (SceneConsts) {
    SceneConsts[SceneConsts["LOADING"] = 0] = "LOADING";
    SceneConsts[SceneConsts["GAME"] = 1] = "GAME";
    SceneConsts[SceneConsts["TEST"] = 2] = "TEST";
    SceneConsts[SceneConsts["FartMonkey"] = 3] = "FartMonkey";
    SceneConsts[SceneConsts["Tarzan"] = 4] = "Tarzan";
    SceneConsts[SceneConsts["Enter"] = 5] = "Enter";
})(SceneConsts || (SceneConsts = {}));
var LayerManager = (function () {
    function LayerManager() {
    }
    /**
     * 游戏背景层
     * @type {BaseSpriteLayer}
     */
    LayerManager.Game_Bg = new core.BaseSpriteLayer();
    /**
     * 主游戏层
     * @type {BaseSpriteLayer}
     */
    LayerManager.Game_Main = new core.BaseSpriteLayer();
    /**
     * UI主界面
     * @type {BaseEuiLayer}
     */
    LayerManager.UI_Main = new core.BaseEuiLayer();
    /**
     * UI弹出框层
     * @type {BaseEuiLayer}
     */
    LayerManager.UI_Popup = new core.BaseEuiLayer();
    /**
     * UI警告消息层
     * @type {BaseEuiLayer}
     */
    LayerManager.UI_Message = new core.BaseEuiLayer();
    /**
     * UITips层
     * @type {BaseEuiLayer}
     */
    LayerManager.UI_Tips = new core.BaseEuiLayer();
    LayerManager.UI_Game = new core.BaseEuiLayer();
    return LayerManager;
}());
__reflect(LayerManager.prototype, "LayerManager");
var TitleMap = (function (_super) {
    __extends(TitleMap, _super);
    function TitleMap() {
        var _this = _super.call(this) || this;
        _this._lookX = 0;
        _this._lookY = 0;
        _this._titles = new Array(16);
        _this._titleWidth = 0;
        _this._titleHeight = 0;
        return _this;
    }
    TitleMap.prototype.initMap = function () {
        for (var i = 0; i < this._titles.length; i++) {
            this._titles[i] = new egret.Bitmap();
            this._titles[i].texture = RES.getRes("bg_png");
            /*
            this._titles[i].filters = [new egret.ColorMatrixFilter([
                1 / (i + 1), 0.6, 0, 0, 0,
                0.3, 0.6, 0, 0, 0,
                0.3, 1 / (i + 1), 0, 0, 0,
                0, 0, 0, 1, 0
            ])]
            */
            this._titles[i].anchorOffsetX = this._titles[i].width / 2;
            this._titles[i].anchorOffsetY = this._titles[i].height / 2;
            this.addChildAt(this._titles[i], i);
            this._titleWidth = this._titles[i].width;
            this._titleHeight = this._titles[i].height;
        }
    };
    TitleMap.prototype.LookAt = function (x, y) {
        this._lookX = x;
        this._lookY = y;
        this.x = core.App.StageUtils.getWidth() / 2 - this._lookX; //- 250
        this.y = core.App.StageUtils.getHeight() / 2 - this._lookY; // - 450
        var indexX = Math.floor(this._lookX / this._titleWidth);
        var indexY = Math.floor(this._lookY / this._titleHeight);
        //console.debug("LookAt(%d, %d)=>(%d, %d)=>((%d, %d)", this._view.x, this._view.y, this._lookX, this._lookY, indexX, indexY)
        //console.debug("(%d, %d)", App.StageUtils.getStage().width, App.StageUtils.getStage().height)
        this._titlePos(0, (indexX) * this._titleWidth, (indexY - 1) * this._titleHeight);
        this._titlePos(1, (indexX) * this._titleWidth, (indexY) * this._titleHeight);
        this._titlePos(2, (indexX) * this._titleWidth, (indexY + 1) * this._titleHeight);
        this._titlePos(3, (indexX) * this._titleWidth, (indexY + 2) * this._titleHeight);
        this._titlePos(4, (indexX - 1) * this._titleWidth, (indexY - 1) * this._titleHeight);
        this._titlePos(5, (indexX - 1) * this._titleWidth, (indexY) * this._titleHeight);
        this._titlePos(6, (indexX - 1) * this._titleWidth, (indexY + 1) * this._titleHeight);
        this._titlePos(7, (indexX - 1) * this._titleWidth, (indexY + 2) * this._titleHeight);
        this._titlePos(8, (indexX + 1) * this._titleWidth, (indexY - 1) * this._titleHeight);
        this._titlePos(9, (indexX + 1) * this._titleWidth, (indexY) * this._titleHeight);
        this._titlePos(10, (indexX + 1) * this._titleWidth, (indexY + 1) * this._titleHeight);
        this._titlePos(11, (indexX + 1) * this._titleWidth, (indexY + 2) * this._titleHeight);
        this._titlePos(12, (indexX + 2) * this._titleWidth, (indexY - 1) * this._titleHeight);
        this._titlePos(13, (indexX + 2) * this._titleWidth, (indexY) * this._titleHeight);
        this._titlePos(14, (indexX + 2) * this._titleWidth, (indexY + 1) * this._titleHeight);
        this._titlePos(15, (indexX + 2) * this._titleWidth, (indexY + 2) * this._titleHeight);
    };
    TitleMap.prototype._titlePos = function (i, x, y) {
        this._titles[i].x = x;
        this._titles[i].y = y;
        //console.debug("====(%d, %d)", x, y)
    };
    return TitleMap;
}(egret.Sprite));
__reflect(TitleMap.prototype, "TitleMap");
var core;
(function (core) {
    var AverageUtils = (function () {
        function AverageUtils(maxNum) {
            if (maxNum === void 0) { maxNum = 10; }
            this.nums = [];
            this.numsLen = 0;
            this.numSum = 0;
            this.maxNum = maxNum;
        }
        AverageUtils.prototype.push = function (value) {
            if (this.numsLen > this.maxNum) {
                this.numsLen--;
                this.numSum -= this.nums.shift();
            }
            this.nums.push(value);
            this.numSum += value;
            this.numsLen++;
        };
        //获取平均数
        AverageUtils.prototype.getValue = function () {
            return this.numSum / this.numsLen;
        };
        AverageUtils.prototype.clear = function () {
            this.nums.splice(0);
            this.numsLen = 0;
            this.numSum = 0;
        };
        return AverageUtils;
    }());
    core.AverageUtils = AverageUtils;
    __reflect(AverageUtils.prototype, "core.AverageUtils");
})(core || (core = {}));
var core;
(function (core) {
    var DebugUtils = (function (_super) {
        __extends(DebugUtils, _super);
        function DebugUtils() {
            var _this = _super.call(this) || this;
            _this._isOpen = true;
            _this._startTimes = {};
            _this._threshold = 3;
            return _this;
        }
        DebugUtils.prototype.setThreshold = function (value) {
            this._threshold = value;
        };
        DebugUtils.prototype.setOpen = function (flag) {
            this._isOpen = flag;
        };
        Object.defineProperty(DebugUtils.prototype, "isDebug", {
            get: function () {
                return this._isOpen;
            },
            enumerable: true,
            configurable: true
        });
        DebugUtils.prototype.start = function (key) {
            if (!this._isOpen) {
                return;
            }
            this._startTimes[key] = egret.getTimer();
        };
        DebugUtils.prototype.stop = function (key) {
            if (!this._isOpen) {
                return 0;
            }
            if (!this._startTimes[key]) {
                return 0;
            }
            var cha = egret.getTimer() - this._startTimes[key];
            if (cha > this._threshold) {
                console.debug(key + ": " + cha);
            }
            return cha;
        };
        return DebugUtils;
    }(core.BaseClass));
    core.DebugUtils = DebugUtils;
    __reflect(DebugUtils.prototype, "core.DebugUtils");
})(core || (core = {}));
var core;
(function (core) {
    var DisplayUtils = (function (_super) {
        __extends(DisplayUtils, _super);
        function DisplayUtils() {
            return _super.call(this) || this;
        }
        DisplayUtils.prototype.createBitmap = function (resName) {
            var result = new egret.Bitmap();
            var texture = RES.getRes(resName);
            result.texture = texture;
            return result;
        };
        DisplayUtils.prototype.createEuiImage = function (resName) {
            var result = new eui.Image();
            var texture = RES.getRes(resName);
            result.source = texture;
            return result;
        };
        DisplayUtils.prototype.removeFromParent = function (child) {
            if (child.parent == null)
                return;
            child.parent.removeChild(child);
        };
        return DisplayUtils;
    }(core.BaseClass));
    core.DisplayUtils = DisplayUtils;
    __reflect(DisplayUtils.prototype, "core.DisplayUtils");
})(core || (core = {}));
var core;
(function (core) {
    var JoyStick = (function (_super) {
        __extends(JoyStick, _super);
        function JoyStick() {
            var _this = _super.call(this) || this;
            _this._backgroud = null;
            _this._btn = null;
            _this._touchBtn = null;
            _this._touchX = 0;
            _this._touchY = 0;
            _this._joyAngle = 0;
            _this._joyRadius = 0;
            _this._joyRadiusPercent = 0;
            _this._joyCenterX = 0;
            _this._joyCenterY = 0;
            _this._maxRadius = 0;
            _this._maxAngle = 0;
            _this._minAngle = 0;
            _this._limitAngle = false;
            _this._verticalJoy = false; //垂直
            _this._horizontalJoy = false; //水平
            return _this;
        }
        Object.defineProperty(JoyStick.prototype, "JoyAngle", {
            get: function () {
                return this._joyAngle;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(JoyStick.prototype, "JoyRadius", {
            get: function () {
                return this._joyRadius;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(JoyStick.prototype, "JoyRadiusPercent", {
            get: function () {
                return this._joyRadius / this._maxRadius;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(JoyStick.prototype, "VerticalJoy", {
            set: function (b) {
                this._verticalJoy = b;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(JoyStick.prototype, "HorizontalJoy", {
            set: function (b) {
                this._horizontalJoy = b;
            },
            enumerable: true,
            configurable: true
        });
        JoyStick.prototype.Init = function (parent, x, y) {
            this._backgroud = new eui.Image;
            this._backgroud.texture = RES.getRes("joystick_bg_png");
            this._joyCenterX = this._backgroud.width / 2;
            this._joyCenterY = this._backgroud.height / 2;
            this._backgroud.touchEnabled = false;
            this.addChildAt(this._backgroud, 0);
            this.anchorOffsetX = this._joyCenterX;
            this.anchorOffsetY = this._joyCenterY;
            this._btn = new eui.Image;
            this._btn.texture = RES.getRes("joystick_btn_png");
            this._btn.anchorOffsetX = this._btn.width / 2;
            this._btn.anchorOffsetY = this._btn.height / 2;
            this._btn.x = this._joyCenterX;
            this._btn.y = this._joyCenterY;
            this._btn.touchEnabled = false;
            this.addChildAt(this._btn, 5);
            this._touchBtn = new eui.Image;
            this._touchBtn.texture = RES.getRes("joystick_btn_png");
            this._touchBtn.anchorOffsetX = this._touchBtn.width / 2;
            this._touchBtn.anchorOffsetY = this._touchBtn.height / 2;
            this._touchBtn.x = this._joyCenterX;
            this._touchBtn.y = this._joyCenterY;
            this._touchBtn.touchEnabled = false;
            this.addChildAt(this._touchBtn, 6);
            this._maxRadius = (this._backgroud.width) / 2 - this._btn.width / 2;
            parent.addChildAt(this, 1000);
            this.x = x;
            this.y = y;
            this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
            this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
            this.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
            this.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.onTouchEnd, this);
            this.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTouchEnd, this);
        };
        JoyStick.prototype.onTouchBegin = function (evt) {
            this._touchX = evt.localX;
            this._touchY = evt.localY;
            this.moveJoyStick(evt.localX, evt.localY);
        };
        JoyStick.prototype.onTouchMove = function (evt) {
            this.moveJoyStick(evt.localX, evt.localY);
            //console.log("===>(%d, %d)", evt.localX, evt.localY)
        };
        JoyStick.prototype.onTouchEnd = function (evt) {
            this.moveJoyStick(this._joyCenterX, this._joyCenterY);
        };
        JoyStick.prototype.moveJoyStick = function (x, y) {
            if (this._touchBtn != null) {
                this._touchBtn.x = x;
                this._touchBtn.y = y;
            }
            if (this._verticalJoy) {
                this._joyRadius = y - this._joyCenterY;
                if (this._joyRadius >= 0) {
                    this._joyAngle = 1;
                }
                else {
                    this._joyAngle = -1;
                    this._joyRadius = -this._joyRadius;
                }
                if (this._joyRadius > this._maxRadius) {
                    this._joyRadius = this._maxRadius;
                }
                this._btn.x = this._joyCenterX;
                this._btn.y = this._joyAngle * this._joyRadius + (this._joyCenterY);
            }
            else if (this._horizontalJoy) {
            }
            else {
                var dx = x - this._joyCenterX;
                var dy = y - this._joyCenterY;
                this._joyRadius = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
                if (this._joyRadius > this._maxRadius) {
                    this._joyRadius = this._maxRadius;
                }
                //let sin = dx * y - x * dy;
                //let cos = dx * x + dy * y;
                this._joyAngle = Math.atan2(dy, dx);
                //while (this._joyAngle < 0) { this._joyAngle += (2 * Math.PI); }
                //while (this._joyAngle > 2 * Math.PI) { this._joyAngle -= (2 * Math.PI); }
                if (this._limitAngle) {
                    if (this._joyAngle >= 0) {
                        if (this._joyAngle > this._maxAngle) {
                            this._joyAngle = this._maxAngle;
                        }
                        if (this._joyAngle < this._minAngle) {
                            this._joyAngle = this._minAngle;
                        }
                    }
                    else {
                        if (-this._joyAngle > this._maxAngle) {
                            this._joyAngle = -this._maxAngle;
                        }
                        if (-this._joyAngle < this._minAngle) {
                            this._joyAngle = -this._minAngle;
                        }
                    }
                }
                this._joyRadiusPercent = this._joyRadius / this._maxRadius;
                this._btn.x = Math.cos(this._joyAngle) * this._joyRadius + (this._joyCenterX);
                this._btn.y = Math.sin(this._joyAngle) * this._joyRadius + (this._joyCenterY);
                console.log("Touch (%d, %d) => (r:%f a:%d)", x - dx, y - dy, this._joyRadiusPercent, this._joyAngle * 180 / Math.PI);
            }
        };
        return JoyStick;
    }(eui.Component));
    core.JoyStick = JoyStick;
    __reflect(JoyStick.prototype, "core.JoyStick");
})(core || (core = {}));
var core;
(function (core) {
    var Log = (function () {
        function Log() {
        }
        Log.getFunctionName = function (func) {
            var name = ('' + func).match(/function\s*([\w\$]*)\s*\(/);
            return name && name[1];
        };
        Log.trace2 = function () {
            var stack = [], caller = arguments.callee.caller;
            while (caller) {
                stack.unshift(Log.getFunctionName(caller));
                caller = caller && caller.caller;
            }
            console.log('functions on stack:' + '\n' + stack.join('\n'));
        };
        Log.trace = function () {
            var caller = arguments.callee.caller;
            var i = 0;
            var count = 20;
            console.log("***----------------------------------------  ** " + (i + 1));
            while (caller && i < count) {
                console.log(caller.toString());
                //console.log(Log.getFunctionName(caller))
                caller = caller.caller;
                i++;
                console.log("***---------------------------------------- ** " + (i + 1));
            }
        };
        Log.error2 = function () {
            var optionalParams = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                optionalParams[_i] = arguments[_i];
            }
            if (core.App.DebugUtils.isDebug) {
                optionalParams[0] = "[DebugLog]" + optionalParams[0] + " at (c:\\code\\server\\trunk\\branch_0\\client\\Titles\\src\\core\\utils\\Log.ts:18:54)";
                console.log.apply(console, optionalParams);
                //Log.trace()
            }
        };
        Log.error = function (arg) {
            try {
                throw new Error();
            }
            catch (e) {
                console.log(arg + "\n" + e.stack);
                var loc = e.stack.replace(/Error\n/).split(/\n/)[1].replace(/^\s+|\s+$/, "");
                console.log("Location: " + loc + "");
            }
        };
        return Log;
    }());
    core.Log = Log;
    __reflect(Log.prototype, "core.Log");
})(core || (core = {}));
var core;
(function (core) {
    var ObjectPool = (function () {
        function ObjectPool() {
            this._objs = new Array();
        }
        ObjectPool.prototype.pushObj = function (obj) {
            this._objs.push(obj);
        };
        ObjectPool.prototype.popObj = function () {
            if (this._objs.length > 0) {
                return this._objs.pop();
            }
            else {
                return null;
            }
        };
        ObjectPool.prototype.clear = function () {
            while (this._objs.length > 0) {
                this._objs.pop();
            }
        };
        ObjectPool.pop = function (refKey) {
            var args = [];
            for (var _i = 1; _i < arguments.length; _i++) {
                args[_i - 1] = arguments[_i];
            }
            if (!ObjectPool._content[refKey]) {
                ObjectPool._content[refKey] = new Array();
            }
            var list = ObjectPool._content[refKey];
            if (list.length) {
                return list.pop();
            }
            else {
                var classZ = egret.getDefinitionByName(refKey);
                var argsLen = args.length;
                var obj;
                if (argsLen == 0) {
                    obj = new classZ();
                }
                else if (argsLen == 1) {
                    obj = new classZ(args[0]);
                }
                else if (argsLen == 2) {
                    obj = new classZ(args[0], args[1]);
                }
                else if (argsLen == 3) {
                    obj = new classZ(args[0], args[1], args[2]);
                }
                else if (argsLen == 4) {
                    obj = new classZ(args[0], args[1], args[2], args[3]);
                }
                else if (argsLen == 5) {
                    obj = new classZ(args[0], args[1], args[2], args[3], args[4]);
                }
                obj.ObjectPoolKey = refKey;
                return obj;
            }
        };
        ObjectPool.push = function (obj) {
            if (obj == null) {
                return false;
            }
            var refKey = obj.ObjectPoolKey;
            if (!ObjectPool._content[refKey]) {
                return false;
            }
            ObjectPool._content[refKey].push(obj);
            return true;
        };
        ObjectPool.clear = function () {
            ObjectPool._content = {};
        };
        ObjectPool._content = {};
        return ObjectPool;
    }());
    core.ObjectPool = ObjectPool;
    __reflect(ObjectPool.prototype, "core.ObjectPool");
})(core || (core = {}));
var core;
(function (core) {
    var ResourceUtils = (function (_super) {
        __extends(ResourceUtils, _super);
        function ResourceUtils() {
            var _this = _super.call(this) || this;
            _this._groupIndex = 0;
            _this._configs = new Array();
            _this._groups = {};
            RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, _this.onResourceLoadComplete, _this);
            RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, _this.onResourceLoadProgress, _this);
            RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, _this.onResourceLoadError, _this);
            return _this;
        }
        //加载配置文件
        ResourceUtils.prototype.addConfig = function (jsonPath, filePath) {
            this._configs.push([jsonPath, filePath]);
        };
        ResourceUtils.prototype.loadConfig = function ($onConfigComplete, $onConfigCompleteTarget) {
            this._onConfigComplete = $onConfigComplete;
            this._onConfigCompleteTarget = $onConfigCompleteTarget;
            this.loadNextConfig();
        };
        ResourceUtils.prototype.loadNextConfig = function () {
            //加载完成
            if (this._configs.length == 0) {
                this._onConfigComplete.call(this._onConfigCompleteTarget);
                this._onConfigComplete = null;
                this._onConfigCompleteTarget = null;
                return;
            }
            var arr = this._configs.shift();
            RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigCompleteHandle, this);
            RES.loadConfig(arr[0], arr[1]);
        };
        ResourceUtils.prototype.onConfigCompleteHandle = function (event) {
            RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigCompleteHandle, this);
            this.loadNextConfig();
        };
        //加载资源
        ResourceUtils.prototype.loadResource = function (resources, groups, onResourceLoadComplete, onResourceLoadProgress, onResourceLoadTarget) {
            if (resources === void 0) { resources = []; }
            if (groups === void 0) { groups = []; }
            if (onResourceLoadComplete === void 0) { onResourceLoadComplete = null; }
            if (onResourceLoadProgress === void 0) { onResourceLoadProgress = null; }
            if (onResourceLoadTarget === void 0) { onResourceLoadTarget = null; }
            var needLoadArr = resources.concat(groups);
            var groupName = "loadGroup" + this._groupIndex++;
            this.loadGroups(groupName, needLoadArr, onResourceLoadComplete, onResourceLoadProgress, onResourceLoadTarget);
            //RES.createGroup(groupName, needLoadArr, true);
            //this._groups[groupName] = [$onResourceLoadComplete, $onResourceLoadProgress, $onResourceLoadTarget];
            //RES.loadGroup(groupName);
        };
        ResourceUtils.prototype.loadGroup = function ($groupName, $onResourceLoadComplete, $onResourceLoadProgress, $onResourceLoadTarget) {
            this._groups[$groupName] = [$onResourceLoadComplete, $onResourceLoadProgress, $onResourceLoadTarget];
            RES.loadGroup($groupName);
        };
        ResourceUtils.prototype.loadGroups = function ($groupName, $subGroups, $onResourceLoadComplete, $onResourceLoadProgress, $onResourceLoadTarget) {
            RES.createGroup($groupName, $subGroups, true);
            this.loadGroup($groupName, $onResourceLoadComplete, $onResourceLoadProgress, $onResourceLoadTarget);
        };
        ResourceUtils.prototype.onResourceLoadComplete = function (event) {
            var groupName = event.groupName;
            if (this._groups[groupName]) {
                var loadComplete = this._groups[groupName][0];
                var loadCompleteTarget = this._groups[groupName][2];
                if (loadComplete != null) {
                    loadComplete.apply(loadCompleteTarget, [groupName]);
                }
                this._groups[groupName] = null;
                delete this._groups[groupName];
            }
        };
        ResourceUtils.prototype.onResourceLoadProgress = function (event) {
            var groupName = event.groupName;
            if (this._groups[groupName]) {
                var loadProgress = this._groups[groupName][1];
                var loadProgressTarget = this._groups[groupName][2];
                if (loadProgress != null) {
                    loadProgress.call(loadProgressTarget, event.itemsLoaded, event.itemsTotal);
                }
            }
        };
        ResourceUtils.prototype.onResourceLoadError = function (event) {
            console.debug(event.groupName + "资源组有资源加载失败");
            this.onResourceLoadComplete(event);
        };
        return ResourceUtils;
    }(core.BaseClass));
    core.ResourceUtils = ResourceUtils;
    __reflect(ResourceUtils.prototype, "core.ResourceUtils");
})(core || (core = {}));
var core;
(function (core) {
    var StageUtils = (function (_super) {
        __extends(StageUtils, _super);
        function StageUtils() {
            var _this = _super.call(this) || this;
            if (StageUtils._uiStage == null) {
                StageUtils._uiStage = new eui.UILayer();
                StageUtils._uiStage.percentHeight = 100;
                StageUtils._uiStage.percentWidth = 100;
                StageUtils._uiStage.touchEnabled = false;
                _this.getStage().addChild(StageUtils._uiStage);
            }
            return _this;
        }
        //获取游戏的全局Stage对象
        StageUtils.prototype.getStage = function () {
            return egret.MainContext.instance.stage;
        };
        //获取游戏宽高
        StageUtils.prototype.getHeight = function () {
            return this.getStage().stageHeight;
        };
        StageUtils.prototype.getWidth = function () {
            return this.getStage().stageWidth;
        };
        //指定此对象的子项以及子孙项是否接收鼠标/触摸事件
        StageUtils.prototype.setTouchChildren = function (value) {
            this.getStage().touchChildren = value;
        };
        //设置同时可触发几个点击事件
        StageUtils.prototype.setMaxTouches = function (value) {
            this.getStage().maxTouches = value;
        };
        //设置帧频
        StageUtils.prototype.setFrameRate = function (value) {
            this.getStage().frameRate = value;
        };
        //设置适配方式
        StageUtils.prototype.setScaleMode = function (value) {
            this.getStage().scaleMode = value;
        };
        //获取根UI容器
        StageUtils.prototype.getUIStage = function () {
            return StageUtils._uiStage;
        };
        StageUtils.prototype.startFullscreenAdaptation = function (designWidth, designHeight, resizeCallback) {
            this.designWidth = designWidth;
            this.designHeight = designHeight;
            this.resizeCallback = resizeCallback;
            this.stageOnResize();
        };
        StageUtils.prototype.stageOnResize = function () {
            this.getStage().removeEventListener(egret.Event.RESIZE, this.stageOnResize, this);
            var designWidth = this.designWidth;
            var designHeight = this.designHeight;
            var clientWidth = window.innerWidth;
            var clientHeight = window.innerHeight;
            var a = clientWidth / clientHeight;
            var b = designWidth / designHeight;
            var c = a / b;
            if (a > b) {
                var c1 = c;
                var c2 = c;
                designWidth = Math.floor(designWidth * c1);
                designHeight = Math.floor(designHeight * c2);
            }
            this.getStage().setContentSize(designWidth, designHeight);
            this.resizeCallback && this.resizeCallback();
            this.getStage().addEventListener(egret.Event.RESIZE, this.stageOnResize, this);
        };
        return StageUtils;
    }(core.BaseClass));
    core.StageUtils = StageUtils;
    __reflect(StageUtils.prototype, "core.StageUtils");
})(core || (core = {}));
var core;
(function (core) {
    var TimerHandler = (function () {
        function TimerHandler() {
            /**执行间隔*/
            this.delay = 0;
            /**重复执行次数*/
            this.repeatCount = 0;
            /**执行时间*/
            this.exeTime = 0;
            /**上次的执行时间*/
            this.dealTime = 0;
        }
        /**清理*/
        TimerHandler.prototype.clear = function () {
            this.method = null;
            this.methodObj = null;
            this.complateMethod = null;
            this.complateMethodObj = null;
        };
        return TimerHandler;
    }());
    core.TimerHandler = TimerHandler;
    __reflect(TimerHandler.prototype, "core.TimerHandler");
    var TimerManager = (function (_super) {
        __extends(TimerManager, _super);
        function TimerManager() {
            var _this = _super.call(this) || this;
            _this._handlers = new Array();
            _this._delHandlers = new Array();
            _this._currTime = egret.getTimer();
            _this._currFrame = 0;
            _this._count = 0;
            _this._timeScale = 1;
            egret.Ticker.getInstance().register(_this.onEnterFrame, _this);
            return _this;
        }
        TimerManager.prototype.setTimeScale = function (timeScale) {
            this._timeScale = timeScale;
            this._currTime = egret.getTimer();
        };
        TimerManager.prototype.onEnterFrame = function () {
            this._currFrame++;
            this._currTime = egret.getTimer();
            var debugKey = "TimerManager:";
            core.App.DebugUtils.start(debugKey);
            for (var i = 0; i < this._count; i++) {
                var handler = this._handlers[i];
                var t = handler.userFrame ? this._currFrame : this._currTime;
                if (t >= handler.exeTime) {
                    core.App.DebugUtils.start(handler.method.toString());
                    handler.method.call(handler.methodObj, (this._currTime - handler.dealTime) * this._timeScale);
                    core.App.DebugUtils.stop(handler.method.toString());
                    handler.dealTime = this._currTime;
                    handler.exeTime += handler.delay;
                    if (!handler.repeat) {
                        if (handler.repeatCount > 1) {
                            handler.repeatCount--;
                        }
                        else {
                            if (handler.complateMethod) {
                                handler.complateMethod.apply(handler.complateMethodObj);
                            }
                            this._delHandlers.push(handler);
                        }
                    }
                }
            }
            while (this._delHandlers.length) {
                var handler = this._delHandlers.pop();
                this.remove(handler.method, handler.methodObj);
            }
            core.App.DebugUtils.stop(debugKey);
        };
        TimerManager.prototype.doTimer = function (delay, repeatCount, method, methodObj, complateMethod, complateMethodObj) {
            if (complateMethod === void 0) { complateMethod = null; }
            if (complateMethodObj === void 0) { complateMethodObj = null; }
            this.create(false, delay, repeatCount, method, methodObj, complateMethod, complateMethodObj);
        };
        TimerManager.prototype.doFrame = function (delay, repeatCount, method, methodObj, complateMethod, complateMethodObj) {
            if (complateMethod === void 0) { complateMethod = null; }
            if (complateMethodObj === void 0) { complateMethodObj = null; }
            this.create(true, delay, repeatCount, method, methodObj, complateMethod, complateMethodObj);
        };
        Object.defineProperty(TimerManager.prototype, "count", {
            get: function () {
                return this._count;
            },
            enumerable: true,
            configurable: true
        });
        TimerManager.prototype.create = function (useFrame, delay, repeatCount, method, methodObj, complateMethod, complateMethodObj) {
            if (delay < 0 || repeatCount < 0 || method == null) {
                return;
            }
            this.remove(method, methodObj);
            var handler = core.ObjectPool.pop("core.TimerHandler");
            handler.userFrame = useFrame;
            handler.repeat = repeatCount == 0;
            handler.repeatCount = repeatCount;
            handler.delay = delay;
            handler.method = method;
            handler.methodObj = methodObj;
            handler.complateMethod = complateMethod;
            handler.complateMethodObj = complateMethodObj;
            //這裏添加的函數不會立即執行，而是等下個周期在運行
            handler.exeTime = delay + (useFrame ? this._currFrame : this._currTime);
            handler.dealTime = this._currTime;
            this._handlers.push(handler);
            this._count++;
        };
        TimerManager.prototype.remove = function (method, methodObj) {
            for (var i = 0; i < this._count; i++) {
                var handler = this._handlers[i];
                if (handler.method == method && handler.methodObj == methodObj) {
                    this._handlers.splice(i, 1);
                    core.ObjectPool.push(handler);
                    this._count--;
                    break;
                }
            }
        };
        TimerManager.prototype.removeAll = function (methodObj) {
            for (var i = 0; i < this._count; i++) {
                var handler = this._handlers[i];
                if (handler.methodObj == methodObj) {
                    this._handlers.splice(i, 1);
                    core.ObjectPool.push(handler);
                    this._count--;
                    i--;
                }
            }
        };
        TimerManager.prototype.isExists = function (method, methodObj) {
            for (var i = 0; i < this._count; i++) {
                var handler = this._handlers[i];
                if (handler.method == method && handler.methodObj == methodObj) {
                    return true;
                }
            }
            return false;
        };
        return TimerManager;
    }(core.BaseClass));
    core.TimerManager = TimerManager;
    __reflect(TimerManager.prototype, "core.TimerManager");
})(core || (core = {}));
;window.Main = Main;window.core = core;